# Maintainer: Caleb Maclennan <caleb@alerque.com>
# # Contributor: Alad Wenter <alad@mailbox.org>

# Contributor: Eli Schwartz <eschwartz@archlinux.org>
# Contributor: Giovanni Scafora <giovanni@archlinux.org>
# Contributor: Larry Hajali <larryhaja [at] gmail [dot] com>

pkgname=sigil
pkgver=2.0.2
pkgrel=1
pkgdesc='multi-platform EPUB2/EPUB3 ebook editor'
arch=('loong64' 'x86_64')
url=https://sigil-ebook.com
_url=https://github.com/Sigil-Ebook/Sigil
license=(GPL3)
depends=(hicolor-icon-theme
         hunspell
         mathjax
         minizip
         python-css-parser
         python-dulwich
         python-lxml
         qt6-5compat
         qt6-svg
         qt6-webengine)
makedepends=(cmake
             qt6-tools)
optdepends=('hunspell-en_US: for English dictionary support'
            'hyphen-en: for English hyphenation support in plugins'
            'pageedit: external editor to replace BookView'
            'pyside6: recommended for plugins'
            'python-html5lib: recommended for plugins'
            'python-chardet: recommended for plugins'
            'python-cssselect: recommended for plugins'
            'python-pillow: recommended for plugins'
            'python-regex: recommended for plugins'
            'tk: recommended for plugins')
_archive="${pkgname^}-$pkgver"
source=("$_url/archive/$pkgver/$_archive.tar.gz"
        "$_url/releases/download/${pkgver}/$_archive.tar.gz.sig")
sha256sums=('d5eaf300dc8307ca0765f9d32d9136e143ca7bcf9e65049499512fdea588e285'
            'SKIP')
validpgpkeys=('B5A56206AB0FBC1A24EFAB8AA166D29A8FCDAC63') # Doug Massay <douglaslmassay@gmail.com>

prepare() {
	cd "$_archive"
	mkdir -p build
}

build() {
	cd "$_archive/build"
	cmake -G "Unix Makefiles" \
		-D USE_SYSTEM_LIBS=1 \
		-D USE_QT6=1 \
		-D SYSTEM_LIBS_REQUIRED=1 \
		-D INSTALL_BUNDLED_DICTS=0 \
		-D INSTALL_HICOLOR_ICONS=1 \
		-D DISABLE_UPDATE_CHECK=1 \
		-D MATHJAX3_DIR=/usr/share/mathjax \
		-D CMAKE_INSTALL_PREFIX=/usr \
		-D CMAKE_INSTALL_LIBDIR=lib \
		-D CMAKE_C_FLAGS="$CFLAGS" \
		-D CMAKE_CXX_FLAGS="$CXXFLAGS" \
		-D CMAKE_SKIP_RPATH=ON ..
	make
}

package() {
	cd "$_archive/build"
	make install DESTDIR="$pkgdir"
	python -m compileall "$pkgdir/usr/share/sigil/"{plugin_launchers/python/,python3lib}
	python -O -m compileall "$pkgdir/usr/share/sigil/"{plugin_launchers/python/,python3lib}
}
